##  This file contains the code to replicate the analyses reported in Table SI-4
##

rm(list = ls(all.names = TRUE))
library(Hmisc)
library(lmtest)
library(sandwich)
library(pscl)
library(MASS)
library(mice)
library(miceadds)
library(openxlsx)


#setwd("~/Dropbox/Current projects/Nazi trials/analysis")
load("Nazi trials replication data.RData")
file.info("Nazi trials replication data.RData")$mtime


##  source helper functions
source("probit2.r")



##
##  Estimate models and save the results
tab1 <- matrix("",29,6)
colnames(tab1) <- paste0("(",1:ncol(tab1),")")

rownames(tab1) <- c(
					"% judges who were appointed in 1933--45", "",
					"% judges who were appointed pre-1933", "",
					"% judges who completed legal training in 1933--45", "",
					"% judges who completed legal training pre-1933", "",
					"avg. share of judges' legal education in 1933--45", "",
					"avg. share of judges' legal education pre-1933", "",
					"% prosecutors who were appointed in 1933--45", "",
					"% prosecutors who were appointed pre-1933", "",
					"% prosecutors who completed legal training in 1933--45", "",
					"% prosecutors who completed legal training pre-1933", "",
					"avg. share of prosecutors' legal education in 1933--45", "",
					"avg. share of prosecutors' legal education pre-1933", "",
					"Year FE","State FE", "Crime categorization FE",
					"$p$-value Wald test % judges","$p$-value Wald test % prosecutors")


##  add additional predictors?
add.pred <- "+ state + JM.party.cont.alt + MP.party.cont.alt + MP2.pro.nazi + MP2.anti.nazi + JM2.pro.nazi + JM2.anti.nazi"



##  col 1
add.pred.MI <- c("NS_judge_@_20","NS_prosecutor_@_20")

##  probit model
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = NULL, wald = NULL)
tab1[c(1,13),1] <- out[[1]][2:3,1]
tab1[c(2,14),1] <- out[[1]][2:3,2]



##  col 2
add.pred.MI <- c("NS_judge_@_20","NS_prosecutor_@_20","NS_judge_@_19","NS_prosecutor_@_19")

##  probit
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = NULL, wald = list(c(1,3),c(2,4)))
tab1[c(1,13,3,15),2] <- out[[1]][2:5,1]
tab1[c(2,14,4,16),2] <- out[[1]][2:5,2]
tab1[28,2] <- out[[2]][1]
tab1[29,2] <- out[[2]][2]



##  col 5
add.pred.MI <- c("NS_judge_@_24","NS_prosecutor_@_24")

##  probit
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = NULL, wald = NULL)
tab1[c(9,21),5] <- out[[1]][2:3,1]
tab1[c(10,22),5] <- out[[1]][2:3,2]



##  col 6
add.pred.MI <- c("NS_judge_@_24","NS_prosecutor_@_24","NS_judge_@_23","NS_prosecutor_@_23")

##  probit
out <- glm.MI(d = cases.temp, outcome = "convicted", add.pred.MI = add.pred.MI, add.pred = add.pred,
sims = NULL, wald = list(c(1,3),c(2,4)))
tab1[c(9,21,11,23),6] <- out[[1]][2:5,1]
tab1[c(10,22,12,24),6] <- out[[1]][2:5,2]
tab1[28,6] <- out[[2]][1]
tab1[29,6] <- out[[2]][2]



##  add checkmarks to table
tab1[25:27,1:6]	<- "\\checkmark"


##  extract only the relevant parts of the results table
tab1[c(1:4,9:16,21:29),c(1:2,5:6)]

latex(tab1[c(1:4,9:16,21:29),c(1:2,5:6)], file = "")



sessionInfo()








.
